// pages/myBaby/myBaby.js
const util = require('../../utils/util.js')
import * as utils from '../../utils/util.js';
Page({
  data: {
    babyList:[],
    ageStr:'',
  },
//获取宝宝列表
getBabyList(){
  utils.HttpRequst(true,'/baby-cloud-base/mobileBabyInfo/listAll','post',{},res=>{
    console.log(res)
    if (res.data.code == 200 && res.data.data.length > 0) {
      var babyList = res.data.data;
      var newbabyList = babyList.slice(0);
      newbabyList.forEach(function (val, ind) {
        val.ageStr = utils.getBirthSlot(val.birthday.split(" ")[0]);
      });
      this.setData({
        babyList: newbabyList,
      })
    }
  })
},
//新增宝宝
openAddBaby() {
  wx.navigateTo({
    url: '/pages/addBaby/addBaby'
  })
},
//编辑宝宝
openEditBaby(e) {
  let item = e.currentTarget.dataset.item
  console.log(e.currentTarget.dataset.item)
  wx.navigateTo({
    url: '/pages/addBaby/addBaby?item=' + encodeURIComponent(JSON.stringify(item))
  })
},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let isLogin = wx.getStorageSync('isLogin')
    if (isLogin){
      this.getBabyList();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})